package chixing.day13.work;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class UerTest {
    private List<User> list;
    private Set<String>  set;
    public UerTest() {
        list = new ArrayList<>();
        set = new HashSet<>();
    }
    public boolean registerUser(User user) {
        // 检查邮箱是否已注册
        if (set.contains(user.getEmail())) {
            return false;
        }

        // 邮箱未注册，添加用户
        list.add(user);
        set.add(user.getEmail());
        return true;
    }
    public List<User> getAllUsers() {
        return list;
    }
    public static void main(String[] args) {
        UerTest uerTest = new UerTest();
        User user1 = new User("<EMAIL1>", "123456");
        User user2 = new User("<EMAIL2>", "123456");
        User user3 = new User("<EMAIL>3", "123456");
        User user4 = new User("<EMAIL1>", "123456");
        System.out.println("用户1注册: " + (uerTest.registerUser(user1) ? "成功" : "失败（邮箱已存在）"));
        System.out.println("用户2注册: " + (uerTest.registerUser(user2) ? "成功" : "失败（邮箱已存在）"));
        System.out.println("用户3注册: " + (uerTest.registerUser(user3) ? "成功" : "失败（邮箱已存在）"));
        System.out.println("用户4注册: " + (uerTest.registerUser(user4) ? "成功" : "失败（邮箱已存在）"));

        // 打印所有注册成功的用户
        System.out.println("\n所有注册成功的用户:");
        for (User user : uerTest.list) {
            System.out.println(user);
        }

    }
}
